package com.fare.util;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

import com.fare.taluo.auth.security.ContextLoginUser;
import com.fare.taluo.auth.security.LogonUserCertificate;

/**
 * 
 * @author 416428406@qq.com
 * 自定义标签加载对应用户所在航空公司的航线
 */
public class CityQueryTag_en_US extends TagSupport {
	/**
	 * 
	 */
	private static final long serialVersionUID = -5139459182505185948L;
	private String msg;
	@Override
	public int doStartTag()  throws JspException {
		try {
			LogonUserCertificate user = ContextLoginUser.getLoginUser();
			String sourceId =user.getSourceKey();
            JspWriter out = this.pageContext.getOut();
            if(msg == null) {
                out.println("No Found...");
                return SKIP_BODY;
            }
            String rootPath = ((HttpServletRequest)pageContext.getRequest()).getContextPath();
            if("super".equals(user.getUserName())){
            	  //加载指定用户的城市数据
                out.println("<script type=\"text/javascript\" src=\""+rootPath+"/fare/js/city/citylist"+"super"+"_en_US"+".js\" charset=\"utf-8\"></script>");
            }else{
            	  //加载指定用户的城市数据
                out.println("<script type=\"text/javascript\" src=\""+rootPath+"/fare/js/city/citylist"+sourceId+"_en_US"+".js\" charset=\"utf-8\"></script>");
            }
          
        } catch(Exception e) {
        	e.printStackTrace();
            throw new JspException(e.getMessage());
        }
		return SKIP_BODY;
	}

	@Override
	public int doEndTag() throws JspException {
		return EVAL_PAGE;
	}

	@Override
	public void release() {
		super.release();
		this.msg = null;
	}
	
	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}
}
